package com.itheima.cs.common.zjdbd;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.Toast;

import com.itheima.cs.R;

import java.lang.ref.WeakReference;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DirectTransferOrderActivity extends AppCompatActivity {

    private ExecutorService executor = Executors.newFixedThreadPool(2);

    private EditText editTextSearch;
    private Handler mainHandler;
    private String scannedMaterialCode = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_direct_transfer_order);
        initView();
    }

    private void initView(){
        editTextSearch = findViewById(R.id.editText_search);

        editTextSearch.requestFocus();

        editTextSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                String input = s.toString();
                if (!TextUtils.isEmpty(input)) {
                    handleScanResult(input);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        mainHandler = new Handler(getMainLooper());
    }

    private void handleScanResult(final String barcode) {

    }


    private void showToastOnMain(Context context, String message) {
        mainHandler.post(() -> {
            if (context instanceof Activity && !((Activity) context).isFinishing()) {
                Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (executor != null && !executor.isShutdown()) {
            executor.shutdownNow();
        }
        mainHandler.removeCallbacksAndMessages(null);
    }



}
